/*
  Copyright � 2009 Smart Enterprise Solution Corp.
  Email: contact@ses.vn - Website: http://www.ses.vn
  ThanhNam ERP Project.
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Data.SqlClient;
using QuocTeViet.DO;
/// <summary>
/// Summary description for cmsLoaiSanPhamDAL
/// </summary>
namespace QuocTeViet.DAL 
{
    
    public class cmsLoaiSanPhamDAL  : BaseDAL
    {
    	#region Private Variables
			
		#endregion
		
		#region Public Constructors
				public cmsLoaiSanPhamDAL()
				{
					//
					// TODO: Add constructor logic here
					//
					
				}
		#endregion       

	
		
		#region Public Methods
        public int Insert(cmsLoaiSanPhamDO objcmsLoaiSanPhamDO)
        {
            
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "spcmsLoaiSanPham_Insert";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@TenLoaiSanPham", SqlDbType.NVarChar);
Sqlparam.Value = objcmsLoaiSanPhamDO.TenLoaiSanPham;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@eTenSanPham", SqlDbType.NVarChar);
Sqlparam.Value = objcmsLoaiSanPhamDO.eTenSanPham;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@MoTa", SqlDbType.NText);
Sqlparam.Value = objcmsLoaiSanPhamDO.MoTa;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@eMoTa", SqlDbType.NText);
Sqlparam.Value = objcmsLoaiSanPhamDO.eMoTa;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@ParentID", SqlDbType.Int);
Sqlparam.Value = objcmsLoaiSanPhamDO.ParentID;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@OrderID", SqlDbType.Int);
Sqlparam.Value = objcmsLoaiSanPhamDO.OrderID;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@Images", SqlDbType.NVarChar);
Sqlparam.Value = objcmsLoaiSanPhamDO.Images;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
Sqlparam.Direction = ParameterDirection.ReturnValue;
Sqlcomm.Parameters.Add(Sqlparam);

           
            int result =base.ExecuteNoneQuery(Sqlcomm);
            
            if(!Convert.IsDBNull(Sqlcomm.Parameters["@ID"]))
				result = Convert.ToInt32(Sqlcomm.Parameters["@ID"].Value);

            return result;
        }

        public int Update(cmsLoaiSanPhamDO objcmsLoaiSanPhamDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsLoaiSanPham_UpdateByPK";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@LoaiSanPhamID", SqlDbType.Int);
            Sqlparam.Value = objcmsLoaiSanPhamDO.LoaiSanPhamID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@TenLoaiSanPham", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsLoaiSanPhamDO.TenLoaiSanPham;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@eTenSanPham", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsLoaiSanPhamDO.eTenSanPham;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@MoTa", SqlDbType.NText);
            Sqlparam.Value = objcmsLoaiSanPhamDO.MoTa;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@eMoTa", SqlDbType.NText);
            Sqlparam.Value = objcmsLoaiSanPhamDO.eMoTa;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ParentID", SqlDbType.Int);
            Sqlparam.Value = objcmsLoaiSanPhamDO.ParentID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@OrderID", SqlDbType.Int);
            Sqlparam.Value = objcmsLoaiSanPhamDO.OrderID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Images", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsLoaiSanPhamDO.Images;
            Sqlcomm.Parameters.Add(Sqlparam);



            Sqlparam = new SqlParameter("@ErrorCode", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);

            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ErrorCode"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ErrorCode"].Value);

            return result;


        }

        public int Delete(cmsLoaiSanPhamDO objcmsLoaiSanPhamDO)
        {
            
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "spcmsLoaiSanPham_DeleteByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@LoaiSanPhamID", SqlDbType.Int);
Sqlparam.Value = objcmsLoaiSanPhamDO.LoaiSanPhamID;
Sqlcomm.Parameters.Add(Sqlparam);


            
            int result=base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

         public int DeleteAll()
        {
            
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "spcmsLoaiSanPham_DeleteAll";

            int result=base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

         public cmsLoaiSanPhamDO Select(cmsLoaiSanPhamDO objcmsLoaiSanPhamDO)
         {

             SqlCommand Sqlcomm = new SqlCommand();
             Sqlcomm.CommandType = CommandType.StoredProcedure;
             Sqlcomm.CommandText = "spcmsLoaiSanPham_GetByPK";
             SqlParameter Sqlparam;


             Sqlparam = new SqlParameter("@LoaiSanPhamID", SqlDbType.Int);
             Sqlparam.Value = objcmsLoaiSanPhamDO.LoaiSanPhamID;
             Sqlcomm.Parameters.Add(Sqlparam);



             DataSet ds = base.GetDataSet(Sqlcomm);
             DataRow dr = null;
             if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
             {
                 dr = ds.Tables[0].Rows[0];
                 if (!Convert.IsDBNull(dr["LoaiSanPhamID"]))
                     objcmsLoaiSanPhamDO.LoaiSanPhamID = Convert.ToInt32(dr["LoaiSanPhamID"]);
                 if (!Convert.IsDBNull(dr["TenLoaiSanPham"]))
                     objcmsLoaiSanPhamDO.TenLoaiSanPham = Convert.ToString(dr["TenLoaiSanPham"]);
                 if (!Convert.IsDBNull(dr["eTenSanPham"]))
                     objcmsLoaiSanPhamDO.eTenSanPham = Convert.ToString(dr["eTenSanPham"]);
                 if (!Convert.IsDBNull(dr["MoTa"]))
                     objcmsLoaiSanPhamDO.MoTa = Convert.ToString(dr["MoTa"]);
                 if (!Convert.IsDBNull(dr["eMoTa"]))
                     objcmsLoaiSanPhamDO.eMoTa = Convert.ToString(dr["eMoTa"]);
                 if (!Convert.IsDBNull(dr["ParentID"]))
                     objcmsLoaiSanPhamDO.ParentID = Convert.ToInt32(dr["ParentID"]);
                 if (!Convert.IsDBNull(dr["OrderID"]))
                     objcmsLoaiSanPhamDO.OrderID = Convert.ToInt32(dr["OrderID"]);
                 if (!Convert.IsDBNull(dr["Images"]))
                     objcmsLoaiSanPhamDO.Images = Convert.ToString(dr["Images"]);

             }
             return objcmsLoaiSanPhamDO;
         }

        public ArrayList SelectAll1( )
        {
			
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "congspcmsLoaiSanPham_GetAll";
            
            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
            ArrayList arrcmsLoaiSanPhamDO = new ArrayList();
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                foreach(DataRow dr in dt.Rows)
{
cmsLoaiSanPhamDO objcmsLoaiSanPhamDO= new cmsLoaiSanPhamDO();
if(!Convert.IsDBNull(dr["LoaiSanPhamID"]))
objcmsLoaiSanPhamDO.LoaiSanPhamID=Convert.ToInt32(dr["LoaiSanPhamID"]);
if(!Convert.IsDBNull(dr["TenLoaiSanPham"]))
objcmsLoaiSanPhamDO.TenLoaiSanPham=Convert.ToString(dr["TenLoaiSanPham"]);
if(!Convert.IsDBNull(dr["eTenSanPham"]))
objcmsLoaiSanPhamDO.eTenSanPham=Convert.ToString(dr["eTenSanPham"]);
if(!Convert.IsDBNull(dr["MoTa"]))
objcmsLoaiSanPhamDO.MoTa=Convert.ToString(dr["MoTa"]);
if(!Convert.IsDBNull(dr["eMoTa"]))
objcmsLoaiSanPhamDO.eMoTa=Convert.ToString(dr["eMoTa"]);
if(!Convert.IsDBNull(dr["ParentID"]))
objcmsLoaiSanPhamDO.ParentID=Convert.ToInt32(dr["ParentID"]);
if(!Convert.IsDBNull(dr["OrderID"]))
objcmsLoaiSanPhamDO.OrderID=Convert.ToInt32(dr["OrderID"]);
if(!Convert.IsDBNull(dr["Images"]))
    objcmsLoaiSanPhamDO.Images = Convert.ToString(dr["Images"]);
arrcmsLoaiSanPhamDO.Add(objcmsLoaiSanPhamDO);
}
            }
               return arrcmsLoaiSanPhamDO;
        }
        
        public DataTable SelectAll( )
        {
			
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "congspcmsLoaiSanPham_GetAll";
            
            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
          
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                
            }
               return dt;
        }

		public DataTable SelectByParent(int id)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsLoaiSanPham_GetByParent";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@id", SqlDbType.Int);
            Sqlparam.Value = id;
            Sqlcomm.Parameters.Add(Sqlparam);

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        public DataTable SelectParent(int id)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsLoaiSanPham_Parent";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@id", SqlDbType.Int);
            Sqlparam.Value = id;
            Sqlcomm.Parameters.Add(Sqlparam);

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
		
		 public DataTable SelectAll(int id)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsLoaiSanPham_GetAll";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@id", SqlDbType.Int);
            Sqlparam.Value = id;
            Sqlcomm.Parameters.Add(Sqlparam);

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
		#endregion          
    
    }

}
